﻿#include "includes\\InputStructures.fx"
#include "includes\\CommonResources.fx"
#include "includes\\StateDefinitions.fx"

float4x4 xCubeTransformationMatrix;
texture2D xCubeTexture;
int xNum;


PsInput_PTNP CubeVS(VsInput_PTN input)
{
	PsInput_PTNP output = (PsInput_PTNP)0;
	
	float4x4 wvpMatrix = mul(xCubeTransformationMatrix, xViewProjectionMatrix);
	output.ScreenPos = mul(input.Pos, wvpMatrix);
	output.UV = input.UV;
	output.Normal = normalize(mul(input.Normal, xCubeTransformationMatrix).xyz);	
	output.Pos3D = mul(input.Pos, xCubeTransformationMatrix).xyz;
	
	return output;
}


float4 CubePS(PsInput_PTNP input) : SV_Target
{
	float3 camVec = normalize(xCameraPosition - input.Pos3D);
	float diff = dot(input.Normal, camVec);
	diff += 1.4f;
	diff /= 2.4f;

	int idx1 = xNum % 3;
	int idx2 = (xNum + 1) % 3;
	int idx3 = (xNum + 2) % 3;
	float4 result = xCubeTexture.Sample(PlanarSampler, input.UV).rgba;
	return float4(result[idx1]*diff, result[idx2]*diff, result[idx3]*diff, result.a);
}

